package com.yxj.dries.ui.my;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.SavedStateHandle;
import androidx.lifecycle.ViewModel;

import com.yxj.dries.data.UserRepository;
import com.yxj.dries.model.User;

import javax.inject.Inject;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author ZSY
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class MyViewModel extends ViewModel {

    private LiveData<User> user;
    private UserRepository userRepository;

    // UserRepository parameter is provided by Dagger
    @Inject
    public MyViewModel(UserRepository repository) {
        this.userRepository = repository;
    }

    public void init(String userId) {
        if (this.user != null) {
            // ViewModel是根据每个Fragment创建的，所以我们知道用户id不会改变
            return;
        }

        user = userRepository.getUser(userId);
    }

}
